package com.scuec.tourismwebsite.mapper;

import com.scuec.tourismwebsite.entity.FreeformPostFavorite;
import com.scuec.tourismwebsite.vo.OfficialFavorite;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface FreeformPostFavoriteMapper {
    @Update("INSERT INTO freeform_post_favorite (post_id, user_id) VALUES (#{post_id}, #{user_id});")
    public int insertFreeformPostFavorite(@Param("user_id") int user_id, @Param("post_id") int post_id);

    @Select("SELECT * FROM freeform_post_favorite where user_id=#{user_id} and post_id=#{post_id}")
    public List<FreeformPostFavorite> selectFreeformPostFavoriteById(@Param("user_id") int user_id, @Param("post_id") int post_id);

    @Delete("DELETE FROM freeform_post_favorite where user_id=#{user_id} and post_id=#{post_id}")
    public int deleteFreeformPostFavorite(@Param("user_id") int user_id, @Param("post_id") int post_id);

    @Select({
            "SELECT ",
            "   f.favorite_id, ",
            "   f.post_id, ",
            "   f.user_id, ",
            "   f.favorite_date, ",
            "   p.title, ",
            "   p.content, ",
            "   p.image_1, ",
            "   p.category, ",
            "   p.post_date, ",
            "   p.views_count, ",
            "   p.likes_count, ",
            "   p.comments_count ",
            "FROM ",
            "   freeform_post_favorite f ",
            "JOIN ",
            "   freeform_post p ON f.post_id = p.post_id ",
            "WHERE ",
            "   f.user_id = #{user_id} "
    })
    List<OfficialFavorite> selectUserOfficialFavorites(@Param("user_id") int user_id);
}
